package com.spring.iosservice.web.service.impl;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.aliyun.oss.OSSClient;
import com.google.common.collect.Maps;
import com.spera.aliyunContent.AliyunContent;
import com.spera.aliyunUtil.CreateOSSClient;
import com.spera.aliyunUtil.SperaOSSUtil;
import com.spera.genutil.TokenUtil;
import com.spring.comment.web.service.CommentService;
import com.spring.common.web.dao.CommonApiMapper;
import com.spring.iosservice.web.dao.IosQuestMapper;
import com.spring.iosservice.web.model.BabyCourseVideo;
import com.spring.iosservice.web.model.CheckUser;
import com.spring.iosservice.web.model.CourseBooks;
import com.spring.iosservice.web.model.CourseImage;
import com.spring.iosservice.web.model.ParentCommentCourse;
import com.spring.iosservice.web.model.StudenetAndComment;
import com.spring.iosservice.web.model.StudentList;
import com.spring.iosservice.web.model.TeacherCareClass;
import com.spring.iosservice.web.model.TeacherCommentBaby;
import com.spring.iosservice.web.model.TeacherCommentCourse;
import com.spring.iosservice.web.model.TeacherCourse;
import com.spring.iosservice.web.model.TeacherVideo;
import com.spring.iosservice.web.service.IosQuestService;
import com.spring.security.core.context.JedisCont;
import com.spring.security.core.util.ApplicationUtils;
import com.spring.security.web.dao.JedisCache;
import com.spring.tools.MyTools;
import com.sso.api.web.dao.SsoMapper;

/**
 * Created by wojunyu on 2015/7/26.
 */
@Service
public class IosQuestServiceImpl implements IosQuestService {
	@Resource
	private IosQuestMapper IosQuestMapper;
	@Resource
	private CommentService commentService;	
	
	@Resource
	private JedisCache jedisCache;
	
	@Resource
	private CommonApiMapper commonApiMapper;
	
	@Resource
	private SsoMapper ssoMapper;

	/**
	 * 
	 * 
	 * @param
	 * @return
	 */
	@Override
	public List<TeacherCourse> getTeacherCousre(String t_user_id,
			String course_time, String course_time_end, String state,
			String get_all,String businessTypeCode,String productCode) {
		HashMap<String, Object> hm = new HashMap<String, Object>();

		if (get_all == null) {
			return null;
		}
		if (get_all.equals("1") || get_all.equals("0")) {
				
			hm.put("businessTypeCode", businessTypeCode);
			hm.put("productCode", productCode);
			
			if (course_time != null) {
				hm.put("t_user_id", t_user_id);
				hm.put("course_time", course_time);
				hm.put("course_time_end", course_time_end);
				hm.put("get_all", get_all);
//				System.out.println("getTeacherCousre" + hm.toString());
				return IosQuestMapper.getTeacherCousre(hm);
			} else if (state.equals("1")) {
				hm.put("t_user_id", t_user_id);
				hm.put("state", state);
				hm.put("get_all", get_all);
//				System.out.println("getTeacherCousre" + hm.toString());
				return IosQuestMapper.getTeacherCousre(hm);
			} else if (state.equals("0")) {
				hm.put("t_user_id", t_user_id);
				hm.put("get_all", get_all);
//				System.out.println("getTeacherCousre" + hm.toString());
				return IosQuestMapper.getTeacherCousre(hm);
			}

		}

		return null;
	}
	
	
	@Override
	public Map<String,Object> getTeacherCareClass(String t_user_id, String productCode,
			String begin_time, String end_time, String state, String token) throws Exception{
		Map<String,Object> retM=new HashMap<String,Object>();
		
	
		HashMap hmc=MyTools.checkIsNotNull(token);
		if(hmc!=null){
			return hmc;
		}
		
		HashMap<String,Object> hm=new HashMap<String,Object>();
		//hm.put("t_user_id", t_user_id);	
		hm.put("productCode", productCode);	
		hm.put("begin_time", begin_time);	
		hm.put("end_time", end_time);	
		hm.put("state", state);	
		
		List<TeacherCareClass> dataset=IosQuestMapper.getTeacherCareClass(hm);	
		
		retM.put(ApplicationUtils.DATASET, dataset);
		retM.put(ApplicationUtils.STATUS, "1");
		retM.put(ApplicationUtils.MSG, "查询成功");
		
		return retM;
		
	}
	
	
	@Override
	public Map<String,Object> getTeacherAllCourse(String t_user_id, String productCode,
			String begin_time, String end_time, String state, String token) throws Exception{
		Map<String,Object> retM=new HashMap<String,Object>();
		
	
		HashMap hmc=MyTools.checkIsNotNull(token);
		if(hmc!=null){
			return hmc;
		}
		
		HashMap<String,Object> hm=new HashMap<String,Object>();
		hm.put("t_user_id", t_user_id);	
		hm.put("productCode", productCode);	
		hm.put("begin_time", begin_time);	
		hm.put("end_time", end_time);	
		hm.put("state", state);	
		
		List<TeacherCareClass> careClass=IosQuestMapper.getTeacherCareClass(hm);	
				
		List<TeacherCourse>  course=this.getTeacherCousre(t_user_id, begin_time, end_time, state, "0", null,productCode);
				
		retM.put("course", course);
		retM.put("care_class", careClass);
		retM.put(ApplicationUtils.STATUS, "1");
		retM.put(ApplicationUtils.MSG, "查询成功");
		
		return retM;
		
	}

	public List<StudentList> getStudenetList(String course_open_detail_id,String unSignOff) {
		HashMap<String, Object> hm = Maps.newHashMap();
		hm.put("course_open_detail_id", course_open_detail_id);
		hm.put("unSignOff", unSignOff);
		return IosQuestMapper.getStudenetList(hm);
	}
	
	public List<StudentList> getStudenetListByClassID(String classId,String unSignOff){
		HashMap<String, Object> hm = Maps.newHashMap();
		hm.put("classId", classId);
		hm.put("unSignOff", unSignOff);		
		return IosQuestMapper.getStudenetListByClassID(hm);
	};
	
	
	public List<StudenetAndComment> getStudenetAndCommentList(String course_open_detail_id){
		
		return IosQuestMapper.getStudenetAndCommentList(course_open_detail_id);
	};
	
	
	public List<CourseBooks> getCousreBooks(String course_id) {

		return IosQuestMapper.getCourseBooks(course_id);

	};

	public List<BabyCourseVideo> getBabyCourseSpec(String user_id,
			String baby_id, String course_open_detail_id) {
		HashMap<String, Object> hm = new HashMap<String, Object>();

		hm.put("t_user_id", user_id);
		hm.put("baby_id", baby_id);
		hm.put("course_open_detail_id", course_open_detail_id);

//		System.out.println("getBabyCourseSpec");
//		System.out.println(hm.toString());

		return IosQuestMapper.getBabyCourseVideo(hm);
	}

	public List<TeacherVideo> getTeacherVideo(String course_video_id) {
//		System.out.println(IosQuestMapper.getTeacherVideo(course_video_id)
//				.size() + "size");
		return IosQuestMapper.getTeacherVideo(course_video_id);
	}
	
	public List<CourseImage> getCourseImage(String course_image_id) {
//		System.out.println(IosQuestMapper.getTeacherVideo(course_image_id)
//				.size() + "size");
		return IosQuestMapper.getCourseImage(course_image_id);
	}

	public void commitComments(String t_user_id, String course_videos_id,
			String course_baby_comments) {
		HashMap<String, Object> hm = new HashMap<String, Object>();
		hm.put("t_user_id", t_user_id);
		hm.put("course_videos_id", course_videos_id);
		hm.put("course_baby_comments", course_baby_comments);
		hm.put("uuid", ApplicationUtils.randomUUID());
		IosQuestMapper.commitComments(hm);
	}
	
	public HashMap<String,Object> commitCourseImageComments(String user_id,String user_type,String user_name, String course_image_id,
			String course_baby_comments) {
		
		HashMap<String,Object> hmr=new HashMap<String,Object>();
		
		HashMap hmc=MyTools.checkIsNotNull(user_id,user_name,course_image_id,course_baby_comments);
		if(hmc!=null){
			return hmc;
		}

		HashMap<String, Object> hm = new HashMap<String, Object>();
		hm.put("user_id", user_id);
		hm.put("user_type", user_type);
		hm.put("user_name", user_name);
		hm.put("course_image_id", course_image_id);
		hm.put("course_baby_comments", course_baby_comments);
		hm.put("uuid", ApplicationUtils.randomUUID());
		int effect=IosQuestMapper.commitCourseImageComments(hm);
		
		if(effect>0){
			hmr.put(ApplicationUtils.STATUS, "1");
			hmr.put(ApplicationUtils.MSG, "插入成功");
		}
		
		return hmr;
	}

	public List<CheckUser> checkUser(String t_user_id) {
		HashMap<String, Object> hm = new HashMap<String, Object>();
		hm.put("t_user_id", t_user_id);
		return IosQuestMapper.checkUser(hm);
	}

	@Override
	public int insertVideos(Map<String, Object> m) {
		// int ret = 0;
		int bv = IosQuestMapper.insertBabyVideos(m);
		String babyids = (String) m.get("c_baby_ids");
		String[] babyidArr = babyids.split(",");
		for (String babyid : babyidArr) {
			m.put("c_baby_id", babyid);
			IosQuestMapper.insertVideos(m);
		}

		return bv;
	}
	
	@Override
	public int insertCourseImages(Map<String, Object> m) {
		// int ret = 0;
		int bv = IosQuestMapper.insertCourseImages(m);
		String babyids = (String) m.get("c_baby_ids");
		String[] babyidArr = babyids.split(",");
		
		for (String babyid : babyidArr) {
			m.put("c_baby_id", babyid);
			IosQuestMapper.insertBabyCourseImages(m);
		}
		return bv;
	}

	@Override
	public int updateTeacher(String t_user_id, String name, String address,
			String birthday, String age, String sex) {
		// TODO Auto-generated method stub
		HashMap<String, Object> hm = new HashMap<String, Object>();

		hm.put("t_user_id", t_user_id);
		hm.put("name", name);
		hm.put("address", address);
		hm.put("birthday", birthday);
		hm.put("age", age);
		hm.put("sex", sex);

		return IosQuestMapper.updateTeacher(hm);

	}

	@Override
	public int updateTeacherImage(String t_user_id, String image_src,
			String root) {
		// TODO Auto-generated method stub

		String image_src_org = IosQuestMapper
				.updateTeacherImageSrcGetOrgan(t_user_id);

		System.out.println("得到删除的图片路径" + root + image_src_org);

		if (image_src_org != null) {
			File f = new File(root + image_src_org);
			if (f.exists()) {
				f.delete();
				System.out.println(image_src_org + "已删除");
			}

		}

		HashMap<String,Object> hm = new HashMap<String,Object>();
		hm.put("t_user_id", t_user_id);
		hm.put("image_src", image_src);
		System.out.println(hm.toString());

		int effect = IosQuestMapper.updateTeacherImageSrc(hm);
		System.out.println(effect + "effect");

		return effect;
	}
	
	@Override
	public int updateTeacherImage(String t_user_id, String image_src) {
		//删除原先的附件
		try{
			String image_src_org = IosQuestMapper
					.updateTeacherImageSrcGetOrgan(t_user_id);
			if(ApplicationUtils.isNotNull(image_src_org)){//删除旧附件
				String imageStr = image_src_org.substring(image_src_org.lastIndexOf("/")+1);
				OSSClient client = CreateOSSClient.getInstance().getOSSClient();
				SperaOSSUtil.deleteObject(client, AliyunContent.fileBucket, imageStr);
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		
		HashMap<String,Object> hm = new HashMap<String,Object>();
		hm.put("t_user_id", t_user_id);
		hm.put("image_src", image_src);
//		System.out.println(hm.toString());
		
		int effect = 0;
		List<CheckUser> checkUser = checkUser(t_user_id);
		if(checkUser!=null&&checkUser.size()>0){
			effect = IosQuestMapper.updateTeacherImageSrc(hm);
		}else{
			hm.put("id", ApplicationUtils.randomUUID());
			effect = IosQuestMapper.insertTeacherImageSrc(hm);
		}

		return effect;
	}

	@Override
	public int updateTeacherPassword(String t_user_id, String old_password,
			String new_password) {
		// TODO Auto-generated method stub

		String o_password = IosQuestMapper
				.updateTeacherPasswordGetOldPassword(t_user_id);

		if (o_password.equals(old_password)) {
			HashMap<String,Object> hm = new HashMap<String,Object>();
			hm.put("t_user_id", t_user_id);
			hm.put("password", new_password);

			int effect = IosQuestMapper.updateTeacherPassword(hm);

			if (effect == 1) {

				return 1;
			} else {

				return 0;
			}

		} else {

			return -1;
		}
	}

	@Override
	public int checkFileToken(Map<String, Object> m) {
		return IosQuestMapper.checkFileToken(m);
	}
	
	@Override
	public int checkImageFileToken(Map<String, Object> m) {
		return IosQuestMapper.checkImageFileToken(m);
	}

	@Override
	public int updateVideoPhoto(Map<String, Object> m, String root) {
		String src = IosQuestMapper.queryVideosPhoto((String) m.get("id"));
		if (src != null) {
//			File f = new File(root + src);
//			if (f.exists()) {
//				f.delete();
//			}
			CreateOSSClient.getInstance().getOSSClient().deleteObject(AliyunContent.inputBucket, src);
		}
		return IosQuestMapper.updateVideoPhoto(m);
	}

	@Override
	public String queryVideosPhoto(String id) {
		return IosQuestMapper.queryVideosPhoto(id);
	}
	
	

	
	/**
	 * 教师对孩子评论
	 */
	@Override
	public Map<String, Object> teacherCommentBaby(String token,String commet,
			String course_open_detail_id,String c_family_member_id,String baby_name,String teacher_name)
			throws Exception {
	// TODO Auto-generated method stub
			Map<String, Object> m = new HashMap<String,Object>();
				
			Map<String, Object> t = TokenUtil.checkToken(token, jedisCache);
			if (t != null) {
				return t;
			}

			String t_user_id = jedisCache.hget(token, TokenUtil.USER_ID);
			
			try {
				
				HashMap<String,Object> hmc=MyTools.checkIsNotNull(commet,course_open_detail_id,c_family_member_id,baby_name,teacher_name);
				if(ApplicationUtils.isNotNull(hmc)){
					return hmc;
				}
				
				HashMap<String,Object> hm=new HashMap<String,Object>();
				hm.put("commet", commet);
				hm.put("course_open_detail_id", course_open_detail_id);
				hm.put("c_family_member_id", c_family_member_id);
				hm.put("baby_name", baby_name);
				hm.put("t_user_id", t_user_id);
				hm.put("teacher_name", teacher_name);
				
				
				//验证是否有这个课
				int count=IosQuestMapper.teacherCommentCourseCheckId(hm);
				
				if(count<1){
					m.put(ApplicationUtils.STATUS, "0");
					m.put(ApplicationUtils.MSG, "请输入有效的课程id");
					return m;
				}
				
				//插入评价
				int effect = IosQuestMapper.teacherCommentBaby(hm);
				
				if(effect!=1){
					m.put(ApplicationUtils.STATUS, "0");
					m.put(ApplicationUtils.MSG, "插入失败");
					return m;
				}
				
				m.put(ApplicationUtils.STATUS, "1");
				m.put(ApplicationUtils.MSG, "查询成功");

			} catch (Exception e) {
				m.put(ApplicationUtils.STATUS, "0");
				m.put(ApplicationUtils.MSG, "系统异常");
				e.printStackTrace();
			}
			return m;
		}
	
	
	/**
	 * 教师对课堂评论
	 */
	@Override
	public Map<String, Object> teacherCommentCourse(String token,String commet,
			String course_open_detail_id,String teacher_name)
			throws Exception {
	// TODO Auto-generated method stub
			Map<String, Object> m = new HashMap<String,Object>();
				
			Map<String, Object> t = TokenUtil.checkToken(token, jedisCache);
			if (t != null) {

				return t;

			}

			String t_user_id = jedisCache.hget(token, TokenUtil.USER_ID);
			
			try {
				
				HashMap<String,Object> hmc=MyTools.checkIsNotNull(commet,course_open_detail_id,teacher_name);
				if(ApplicationUtils.isNotNull(hmc)){
					return hmc;
				}
				
				
				HashMap<String,Object> hm=new HashMap<String,Object>();
				hm.put("commet", commet);
				hm.put("course_open_detail_id", course_open_detail_id);
				hm.put("t_user_id", t_user_id);
				hm.put("teacher_name", teacher_name);
				
				//验证是否有这个课
				int count=IosQuestMapper.teacherCommentCourseCheckId(hm);
				
				if(count<1){
					m.put(ApplicationUtils.STATUS, "0");
					m.put(ApplicationUtils.MSG, "请输入有效的课程id");
					return m;
				}
				//插入评价
				int effect = IosQuestMapper.teacherCommentCourse(hm);
				
				if(effect!=1){
					m.put(ApplicationUtils.STATUS, "0");
					m.put(ApplicationUtils.MSG, "插入失败");
					return m;
				}
				
				m.put(ApplicationUtils.STATUS, "1");
				m.put(ApplicationUtils.MSG, "插入成功");

			} catch (Exception e) {
				m.put(ApplicationUtils.STATUS, "0");
				m.put(ApplicationUtils.MSG, "系统异常");
				e.printStackTrace();
			}
			return m;
		}
	


	
	/**
	 * 得到教师对孩子的评论
	 */
	@Override
	public Map<String, Object> getTeacherCommentBabyList(String token,String course_open_detail_id,String c_user_id,String page_size,
			String page_index,String skip,String rows) throws Exception {
	// TODO Auto-generated method stub
			Map<String, Object> m = new HashMap<String,Object>();
				
			Map<String, Object> t = TokenUtil.checkToken(token, jedisCache);
			if (t != null) {

				return t;

			}

			String t_user_id = jedisCache.hget(token, TokenUtil.USER_ID);
			
			try {
				
				HashMap<String,Object> hmc=MyTools.checkIsNotNull(course_open_detail_id);
				if(ApplicationUtils.isNotNull(hmc)){
					return hmc;
				}
				
				HashMap<String,Object> hm=MyTools.pageIndexToSkip(page_size, page_index, skip, rows);
				
				hm.put("course_open_detail_id", course_open_detail_id);
				hm.put("t_user_id", t_user_id);
				hm.put("c_user_id", c_user_id);
				
				
				
				List<TeacherCommentBaby> list=IosQuestMapper.getTeacherCommentBabyList(hm);
				
				m.put(ApplicationUtils.DATASET, list);
				m.put(ApplicationUtils.STATUS, "1");
				m.put(ApplicationUtils.MSG, "查询成功");

			} catch (Exception e) {
				m.put(ApplicationUtils.STATUS, "0");
				m.put(ApplicationUtils.MSG, "系统异常");
				e.printStackTrace();
			}
			return m;
		}
	
	
	/**
	 * 得到教师对孩子的评论
	 */
	@Override
	public Map<String, Object> getTeacherCommentBabyListNew(String token,String course_open_detail_id,String c_user_id,String page_size,
			String page_index,String skip,String rows) throws Exception {
	// TODO Auto-generated method stub
			Map<String, Object> m = new HashMap<String,Object>();
				
			Map<String, Object> t = TokenUtil.checkToken(token, jedisCache);
			if (t != null) {

				return t;

			}

			String t_user_id = jedisCache.hget(token, TokenUtil.USER_ID);
			
			try {
				
				HashMap<String,Object> hmc=MyTools.checkIsNotNull(course_open_detail_id);
				if(ApplicationUtils.isNotNull(hmc)){
					return hmc;
				}
				
				//Map<String, Object> 
				m= commentService.getCommentCustomer("1002", course_open_detail_id, c_user_id, t_user_id, "3", page_size, page_index, skip, rows);

			} catch (Exception e) {
				m.put(ApplicationUtils.STATUS, "0");
				m.put(ApplicationUtils.MSG, "系统异常");
				e.printStackTrace();
			}
			return m;
		}
	
	
	
	
	
	
	
	/**
	 * 查看教师对课程的评论
	 */
	@Override
	public Map<String, Object> getTeacherCommentCourseList(String token,String course_open_detail_id,String page_size,
			String page_index,String skip,String rows) throws Exception {
	// TODO Auto-generated method stub
			Map<String, Object> m = new HashMap<String,Object>();
				
			Map<String, Object> t = TokenUtil.checkToken(token, jedisCache);;
			if (t != null) {

				return t;

			}

			String t_user_id = jedisCache.hget(token, TokenUtil.USER_ID);
			
			try {
				
				HashMap<String,Object> hmc=MyTools.checkIsNotNull(course_open_detail_id);
				if(ApplicationUtils.isNotNull(hmc)){
					return hmc;
				}
				
				HashMap<String,Object> hm=MyTools.pageIndexToSkip(page_size, page_index, skip, rows);
				
				hm.put("course_open_detail_id", course_open_detail_id);
				hm.put("t_user_id", t_user_id);
				
				
				List<TeacherCommentCourse> list=IosQuestMapper.getTeacherCommentCourseList(hm);
				
				m.put(ApplicationUtils.DATASET, list);
				m.put(ApplicationUtils.STATUS, "1");
				m.put(ApplicationUtils.MSG, "查询成功");

			} catch (Exception e) {
				m.put(ApplicationUtils.STATUS, "0");
				m.put(ApplicationUtils.MSG, "系统异常");
				e.printStackTrace();
			}
			return m;
		}
	
	
	/**
	 * 得到教师对孩子的评论
	 */
	@Override
	public Map<String, Object> getTeacherCommentCourseListNew(String token,String course_open_detail_id,String page_size,
			String page_index,String skip,String rows) throws Exception{
	// TODO Auto-generated method stub
			Map<String, Object> m = new HashMap<String,Object>();
				
			Map<String, Object> t = TokenUtil.checkToken(token, jedisCache);;
			if (t != null) {

				return t;

			}

			String t_user_id = jedisCache.hget(token, TokenUtil.USER_ID);
			
			try {
				
				HashMap<String,Object> hmc=MyTools.checkIsNotNull(course_open_detail_id);
				if(ApplicationUtils.isNotNull(hmc)){
					return hmc;
				}
				
				//Map<String, Object> 
			//	m= commentService.getCommentCustomer("1001", course_open_detail_id, c_user_id, t_user_id, "3", page_size, page_index, skip, rows);
				//commentService.getCommentService(businessTypeCode, serviceID, userID, serviceModuleCode, pageSize, pageIndex, skip, rows)
				
				
				m= commentService.getCommentService("1002", course_open_detail_id, null, "1", page_size, page_index, skip, rows);
				
				
			} catch (Exception e) {
				m.put(ApplicationUtils.STATUS, "0");
				m.put(ApplicationUtils.MSG, "系统异常");
				e.printStackTrace();
			}
			return m;
		}
	
	
	
	@Override
	public Map<String, Object> getParentCommentCourseList(String token,String course_open_detail_id,String page_size,
			String page_index,String skip,String rows) throws Exception {
	// TODO Auto-generated method stub
			Map<String, Object> m = new HashMap<String,Object>();
				
			Map<String, Object> t = TokenUtil.checkToken(token, jedisCache);;
			if (t != null) {

				return t;

			}

			String t_user_id = jedisCache.hget(token, TokenUtil.USER_ID);
			
			try {
				
				HashMap<String,Object> hmc=MyTools.checkIsNotNull(course_open_detail_id);
				if(ApplicationUtils.isNotNull(hmc)){
					return hmc;
				}
				
				HashMap<String,Object> hm=MyTools.pageIndexToSkip(page_size, page_index, skip, rows);
				
				hm.put("course_open_detail_id", course_open_detail_id);
				hm.put("t_user_id", t_user_id);
				
				
				List<ParentCommentCourse> list=IosQuestMapper.getParentCommentCourseList(hm);
				
				m.put(ApplicationUtils.DATASET, list);
				m.put(ApplicationUtils.STATUS, "1");
				m.put(ApplicationUtils.MSG, "查询成功");

			} catch (Exception e) {
				m.put(ApplicationUtils.STATUS, "0");
				m.put(ApplicationUtils.MSG, "系统异常");
				e.printStackTrace();
			}
			return m;
		}
	
	
	
	@Override
	public Map<String, Object> getParentCommentCourseListNew(String token,String course_open_detail_id,String page_size,
			String page_index,String skip,String rows) throws Exception {
	// TODO Auto-generated method stub
			Map<String, Object> m = new HashMap<String,Object>();
				
			Map<String, Object> t = TokenUtil.checkToken(token, jedisCache);;
			if (t != null) {

				return t;

			}

			String t_user_id = jedisCache.hget(token, TokenUtil.USER_ID);
			
			try {
				
				HashMap<String,Object> hmc=MyTools.checkIsNotNull(course_open_detail_id);
				if(ApplicationUtils.isNotNull(hmc)){
					return hmc;
				}
				
						
				m= commentService.getCommentService("1002", course_open_detail_id, null, "2", page_size, page_index, skip, rows);
				
				
//				HashMap<String,Object> hm=MyTools.pageIndexToSkip(page_size, page_index, skip, rows);
//				
//				hm.put("course_open_detail_id", course_open_detail_id);
//				hm.put("t_user_id", t_user_id);
//				
//				
//				List<ParentCommentCourse> list=IosQuestMapper.getParentCommentCourseList(hm);
//				
//				m.put(ApplicationUtils.DATASET, list);
//				m.put(ApplicationUtils.STATUS, "1");
//				m.put(ApplicationUtils.MSG, "查询成功");

			} catch (Exception e) {
				m.put(ApplicationUtils.STATUS, "0");
				m.put(ApplicationUtils.MSG, "系统异常");
				e.printStackTrace();
			}
			return m;
		}
	

	// 检查token
	private Map<String, Object> checkToken(String token) {
		Map<String, Object> s = new HashMap<String, Object>();
		if (!ApplicationUtils.isNotNull(token)) {
			s.put(ApplicationUtils.STATUS, "0");
			s.put(ApplicationUtils.MSG, "请先登录");
			return s;
		} else {
			if (!jedisCache.exists(token)) {
				s.put(ApplicationUtils.STATUS, "-9999");
				s.put(ApplicationUtils.MSG, "用户登录已失效，请先重新登录");
				return s;
			} else {
				jedisCache.expire(token, JedisCont.JEDIS_EXPRISE);
				return null;
			}
		}
	}
	
	//ipad上传同步添加到个人空间
	@Override
	public Map<String, Object> createIOSPhotoJournal(String url,String ossKey,String babys) {
	// TODO Auto-generated method stub
		//插入base_oss_file
		
		Map<String, Object> m=new HashMap<String, Object>();
		
		String fileID=ApplicationUtils.randomUUID();
		
		HashMap<String,Object> hmp=new HashMap<String,Object>();
		hmp.put("fileID", fileID);
		hmp.put("url", url);
		hmp.put("osskey", ossKey);
		hmp.put("bucket", AliyunContent.inputBucket);
		
		int effect=commonApiMapper.createFile(hmp);
		
		
		String[] userList = babys.split(",");
		
		
		
		for (String babyid : userList) {
			
			String journalID=ApplicationUtils.randomUUID();
		
			HashMap<String,Object> hm2=new HashMap<String,Object>();
			hm2.put("title", "教学日志");
			hm2.put("content", "教学日志");
			hm2.put("c_user_id",babyid);
			hm2.put("journalID",journalID);
			hm2.put("fileID",fileID);
						
			HashMap r= ssoMapper.getUserByID(babyid);
			if(r!=null){
				hm2.putAll(r);
				
				int effect3=IosQuestMapper.insertJournal(hm2);
				
				int effect4=IosQuestMapper.insertJournalPhoto(hm2);
			}

		}

		m.put(ApplicationUtils.STATUS, 1);
		m.put(ApplicationUtils.MSG, "添加成功");
		
		return m;
		}
	
	
	//ipad上传同步添加到个人空间
		@Override
		public Map<String, Object> createIOSVideoJournal(String videoID,String osskey,String babys) {
		// TODO Auto-generated method stub
			//插入base_oss_file
			
//			String userList=one.getBabyIDs();
//			
//			String videoID=one.getCourseVideosId();
			
			Map<String, Object> m=new HashMap<String, Object>();
			
			String baseVideoID=ApplicationUtils.randomUUID();
			String basephotoID=ApplicationUtils.randomUUID();	
			HashMap<String, Object> video =IosQuestMapper.getVideoByID(videoID);	
	
		//	video.put("videoID", baseVideoID);
			
			String video_url=MyTools.ObjectToString(video.get("video_url"));
			String video_token=MyTools.ObjectToString(video.get("video_token"));
			String photo_url=MyTools.ObjectToString(video.get("photo_url"));
			
			//插入图片
			HashMap<String,Object> hmp=new HashMap<String,Object>();
			hmp.put("fileID", basephotoID);
			hmp.put("url", photo_url);
			
			int effect=commonApiMapper.createFile(hmp);
			
			HashMap<String,Object> hmp2=new HashMap<String,Object>();
			hmp2.put("videoID", baseVideoID);
			hmp2.put("url", video_url);
			hmp2.put("photoID", basephotoID);
						
			int effect2=IosQuestMapper.insertBaseVidoe(hmp2);
			
			System.out.println(babys);
			
			if(babys!=null||!babys.equals("")){
			
			String[] userList = babys.split(",");
			
			for (String babyid : userList) {						
				
				String journalID=ApplicationUtils.randomUUID();
			
				HashMap<String,Object> hm2=new HashMap<String,Object>();
				hm2.put("title", "教学日志");
				hm2.put("content", "教学日志");
				hm2.put("c_user_id",babyid);
				hm2.put("journalID",journalID);
				hm2.put("fileID",baseVideoID);
		
				HashMap r= ssoMapper.getUserByID(babyid);
				
				hm2.put("member_name","教师");
				
				if(r!=null){
				
				hm2.putAll(r);
				
				int effect3=IosQuestMapper.insertJournal(hm2);
				
				int effect4=IosQuestMapper.insertJournalVideo(hm2);
				}
				
			}
			}
			m.put(ApplicationUtils.STATUS, 1);
			m.put(ApplicationUtils.MSG, "添加成功");
			
			return m;
			}

		@Override
		public List<StudentList> getProStudenetList(String productId,
				String unSignOff) {
			HashMap<String, Object> hm = Maps.newHashMap();
			hm.put("productId", productId);
			hm.put("unSignOff", unSignOff);
			return IosQuestMapper.getProStudenetList(hm);
		}

		@Override
		public List<StudentList> getCareStudenetList(String care_class_id,
				String unSignOff) {
			HashMap<String, Object> hm = Maps.newHashMap();
			hm.put("care_class_id", care_class_id);
			hm.put("unSignOff", unSignOff);
			return IosQuestMapper.getCareStudenetList(hm);
		}
}
